<template>
  <div class="app-container form_body">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="部门名称" prop="name">
    <el-input v-model="ruleForm.name"></el-input>
  </el-form-item>
  

 

  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        ruleForm: {
          name: ''
  
  
        },
        rules: {
          name: [
            { required: true, message: '请输入名称', trigger: 'blur' },
            { min: 1, max: 85, message: '长度在 1 到 85 个字符', trigger: 'blur' }
          ]
  
        }
      }
  },
    methods: {
      submitForm(formName) {
        var that = this
  
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const data = {
              'pname': that.ruleForm.name
            }
            that.$request({
              url: '/admin/add_department',
              method: 'post',
              data
            }).then(res => {
              console.log(res)
              if (res.code == 200) {
                that.$message({ message: '添加部门成功!', type: 'success' })
                  that.ruleForm.name = ''
              }
            })
          } else {
            console.log('error submit!!')
          return false
        }
        })
    },
      resetForm(formName) {
        this.$refs[formName].resetFields()
    }
    }
  }
</script>
<style  scoped>
.form_body{
  width: 330px;
  height: auto;
}
</style>
